﻿using System;
using System.Collections.Specialized;
using System.Configuration;

namespace SharedGenomics.Core.Configuration
{
    public class DefaultConfigurationReader : ConfigurationReaderBase
    {
        private readonly NameValueCollection _appSettings;
        private readonly ConnectionStringSettingsCollection _connectionStrings;

        public DefaultConfigurationReader(NameValueCollection appSettings, ConnectionStringSettingsCollection connectionStrings)
        {
            appSettings.ThrowIfNull("appSettings");
            connectionStrings.ThrowIfNull("connectionStrings");

            this._appSettings = appSettings;
            this._connectionStrings = connectionStrings;
        }

        public override string GetConnectionString(string connectionStringName)
        {
            connectionStringName.ThrowIfNull("connectionStringName");
            var connectionString = this._connectionStrings[connectionStringName];

            return connectionString == null ? null : connectionString.ConnectionString;
        }

        public override string GetAppSetting(string settingName)
        {
            settingName.ThrowIfNull("settingName");
            return this._appSettings[settingName];
        }
    }
}
